var jid
layui.use(['form', 'element'], function () {
    var element = layui.element;
    var form = layui.form;
    setTimeout(function () {
        $('.site-zfj').addClass('site-zfj-anim');
        setTimeout(function () {
            $('.site-desc').addClass('site-desc-anim')
        }, 5000)
    }, 100);

    form.on('submit(search)', function (data) {
        var keyword = $("#keyword").val();
        if (keyword == "") {
            xiaoxi("请填写需要搜索的关键词", 2, "输入错误");
            return false;
        } else {
            tishi();
            search(keyword);
        }
        return false;
    });

});

function tishi() {
    jid = layer.open({
        type: 1,
        title: false,
        closeBtn: 0,
        shadeClose: false,
        area: ['200px', '110px'],
        content: '<div class="spinner"><div class="bounce1"></div><div class="bounce2"></div><div class="bounce3"></div></div><div class="tlitle">后台正在分析中....</div>'
    });
}

function search(key) {
    $.ajax({
        url: '/dati/search/ByKeyWord',
        data: {"key": key},
        type: "POST",
        success: function (data) {
            layer.close(jid);
            if (data.code == 200) {
                //xiaoxi(data.msg, 2, "success");
                $("#search-bai-du").text("关键词:" + key);
                var result = "";
                var list = data.data[0].answer;
                for (var item = 0; item < list.length; item++) {
                    result += '<tr onclick="">';
                    result += '<td><a href="">' + list[item] + '</a></td>';
                    result += '</tr>';
                }
                $("#search-bai-du-tbody").html("");
                $("#search-bai-du-tbody").html(result);
                return;
            }
            if (data.code == 2) {
                location.href = data.url;
                return;
            }
        }
    });
}

function xiaoxi(msg, ico, title) {
    layer.alert(msg, {
        icon: ico,
        title: title,
    })
}
 
